package com.hns.can.energy.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.energy.vo.NewEnergy;
import com.hns.can.master.entity.CommEnerConsStatInfoEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 驾驶行为分析service
 * @author:zhangy
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class DrvBehaviorAnalysisService extends CommonService {
	
	@Autowired
	private FillCodeDscValue fillCodeDscValue;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@LeftOrgAnnotation()
    @Transactional
    public Pagination searchDrvBehaviorAnalysis(NewEnergy vo)throws Exception {
        Pagination page = this.myBatisPage("drvBehaviorAnalysis.searchDrvBehaviorAnalysisCount", "drvBehaviorAnalysis.searchDrvBehaviorAnalysis", vo, CommEnerConsStatInfoEntity.class);
        List list = page.getData();
        fillColVal(list);
        page.setData(list);
        return page;
    }

	/**
     * 
     * @param vo
     * @param request
     * @return
     * @throws QueryExprException
     * @author:Lan
     * @email:763836737@qq.com
     * @创建日期:2014-10-30
     * @功能说明：导出
     */
     @LeftOrgAnnotation()
     @Transactional
     @SuppressWarnings({ "unchecked" })
     public  List<CommEnerConsStatInfoEntity> exportDrvBehaviorAnalysis(NewEnergy vo)throws Exception {
         List<CommEnerConsStatInfoEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("drvBehaviorAnalysis.searchDrvBehaviorAnalysis", vo), CommEnerConsStatInfoEntity.class);
         fillColVal(list);
         return list;
     }
	
     /**
      * 填充字段值
      * @param list
      * @throws Exception
      * @author:zhangy
      * @email:zhangyu2222z@sina.cn
      */
     @SuppressWarnings("rawtypes")
	private void fillColVal(List list) throws Exception {
 		//转化生成线路名称
         Map<String,String> map = new HashMap<String,String>();
         map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
         FillParamsVo fileVo1 = new FillParamsVo("lineId", map);
         //转化生成机构名称
         map = new HashMap<String,String>();
         map.put("organName",  GlobalConst.DEFAULT_CACHE_VALUE);
         FillParamsVo fileVo2 = new FillParamsVo("organId", map);
         //转化生成车牌号、车辆类别、车辆、燃料类型
         map= new HashMap<String,String>();
         map.put("licPltNo",  GlobalConst.DEFAULT_CACHE_VALUE);
         map.put("carType", "carType");
         map.put("carInCd", "carInCd");
         map.put("engiNo", "engiNo");
         //转化生成驾驶员名称
         FillParamsVo fileVo3 = new FillParamsVo("carId", map);
         map = new HashMap<String,String>();
         map.put("drvName",  GlobalConst.DEFAULT_CACHE_VALUE);
         FillParamsVo fileVo4 = new FillParamsVo("drvId", map);
         fillCodeDscValue.fillInfoValue(list,new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO, 
             GlobalConst.CACHE_KEY_BASE_DRV_INFO, GlobalConst.CACHE_KEY_BASE_ORGAN, 
             GlobalConst.CACHE_KEY_BASE_CAR_INFO}, fileVo1, fileVo2, fileVo3, fileVo4);
 	}

     /**
      * 图表数据
      * @param vo
      * @param request
      * @return
      * @throws Exception
      * @author:zhangy
      * @email:zhangyu2222z@sina.cn
      */
     @Transactional
     @SuppressWarnings({ "unchecked" })
     public  List<CommEnerConsStatInfoEntity> searchLineEnergyChart(NewEnergy vo,HttpServletRequest request)throws Exception {
         List<CommEnerConsStatInfoEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("drvBehaviorAnalysis.searchLineEnergyChart", vo), CommEnerConsStatInfoEntity.class);
         fillColVal(list);
         return list;
     }
     
     
}
